/**
 * 
 */
package com.hq.cms.web.controllers.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.cms.domain.Link;
import com.hq.cms.service.ArticleService;
import com.hq.cms.service.LinkService;
import com.hq.cms.service.UserInfoService;

/**
 * 说明:
 * 
 * @author howsun ->[howsun.zhang@gmail.com]
 * @version 1.0
 *
 * 2019年3月29日 下午6:54:11
 */
@Controller
@RequestMapping("/admin")
public class AdminHomeController {
	@Resource
	private UserInfoService userInfoService;
	@Resource
	private ArticleService articleService;
	@Resource
	private LinkService linkService;
	
	@RequestMapping({"/", "/index"})
	public String home(){
		return "admin/home";
	}
	@RequestMapping("/userManager")
	public String userManager(Model model,@RequestParam(value="cpage",defaultValue="1")Integer cpage) {
		Map map=new HashMap();
		PageHelper.startPage(cpage,5);
		List  list=userInfoService.userManager(map);
		
		PageInfo pi = new PageInfo(list);
		model.addAttribute("list", list);
		model.addAttribute("pi", pi);
		return "admin/user-manage";
	}
	
	@RequestMapping("/changeLocked")
	@ResponseBody
	public Object changeLocked(Integer id) {
		int i=userInfoService.changeLocked(id);
		
		return i;
	}
	
	@RequestMapping("/blogManager")
	public String blogManger(Model model,@RequestParam(value="cpage",defaultValue="1")Integer cpage) {
		Map map=new HashMap();
		PageHelper.startPage(cpage,10);
		List list=articleService.blogList(map);
		PageInfo pi=new PageInfo(list);
		model.addAttribute("list", list);
		model.addAttribute("pi", pi);
		return "admin/blog-manage";
	}
	
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Object changeStatus(Integer id) {
		
		int i=articleService.changeStatus(id);
		return i;
	}
	
	@RequestMapping("/addLink")
	public String  toAddLink() {
		
		return "admin/link";
	}
	@RequestMapping("/doAddLink")
	public String doAddLink(Link link) {
		int i=linkService.doAddLink(link);
		return "redirect:/admin/";
	}
	@RequestMapping("/linkList")
	@ResponseBody
	public Object LinkList() {
		List list=linkService.linkList();
		return list;
	}
}
